<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页</title>
    <link rel="stylesheet" th:href="@{/layui-v2.6.8/css/layui.css}" href="/static/layui-v2.6.8/css/layui.css">
<style>
.layui-input-width{
     width: 20%;
}
.form-position{
    margin-left: 35%;
    margin-top: 15%;
}
</style>
</head>
<body>
<form class="layui-form form-position" action="/amin/login" method="post" id="amin-login-form">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input layui-input-width">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密&emsp;码</label>
        <div class="layui-input-block">
            <input type="password" name="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input layui-input-width">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">登录</button>
            <a th:href="@{/registration}">
            <button type="button" class="layui-btn layui-btn-primary">注册</button>
            </a>
        </div>
    </div>
</form>
</body>
<!-- 引入 layui.js -->
<script th:src="@{/layui-v2.6.8/layui.js}" src="/static/layui-v2.6.8/layui.js"></script>
<script th:src="@{/jquery-3.5.1/jquery-3.5.1.min.js}" src="/static/jquery-3.5.1/jquery-3.5.1.min.js"></script>
<script th:src="@{/js/common-0.0.1.js}" src="/static/js/common-0.0.1.js"></script>
<script>
    function require(s) {
        return s
    }
    //const {postRequestLogin} = require("../static/js/common-0.0.1");
    layui.use(function(){
        const layer = layui.layer
            , form = layui.form;
    //监听提交
    form.on('submit(formDemo)', function(data){
        console.log(data);
        const url = "/amin/login";
        layer.msg('操作成功，正在跳转......');
        const login_form_data = $("#amin-login-form").serialize();
        $.ajax({
            type: "POST",
            dataType: "json",
            url: url ,
            data: login_form_data,
            success: function (result) {
                console.log(result)
                token = result.token;
                return result;
                /*if(1000 == result.code){
                    return result.token;
                }else{
                    return result.data;
                }*/
            },
            error : function() {
                return "系统异常";
            }
        });
        //postRequestLogin(url,login_form_data)
        //return true;
    });
});
</script>
</html>